package com.assignwork.dto;

import com.assignwork.entity.ThroughputForecast;
import com.assignwork.entity.ThroughputForecastItem;
import lombok.Data;
import org.springblade.core.tool.utils.Func;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
public class ThroughputForecastDTO extends ThroughputForecast {

    public static final String I_E_TYPE = "ie_type";
    public static final String BERTH = "berth";
    public static final String TRADE_TYPE = "trade_type";
    public static final String PERIOD_TEN_DAYS = "period_ten_days";

    private String year;
    private String month;
    private String statisticsType;
    private List<ThroughputForecastItemDTO> cargoTon;

    public List<ThroughputForecastItem> getCargoTonEtt() {
        List<ThroughputForecastItem> res = new ArrayList<>();
        if (Func.isNotEmpty(cargoTon)) {
            for (ThroughputForecastItemDTO item : cargoTon) {
                item.setParentId(getId());
                ThroughputForecastItem copy = Func.copy(item, ThroughputForecastItem.class);
                res.add(copy);
            }
        }
        return res;
    }

    @Override
    public String getPeriodTenDays() {
        LocalDateTime endTime = getEndTime();
        if (endTime != null) {
            int dom = endTime.getDayOfMonth();
            if (dom <= 10) {
                setPeriodTenDays("1");
            } else if (dom <= 20) {
                setPeriodTenDays("2");
            } else {
                setPeriodTenDays("3");
            }
        }
        return super.getPeriodTenDays();
    }
}
